<html>
<head><meta charset="utf-8"><title>Span niche · t-compiler/performance · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/index.html">t-compiler/performance</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html">Span niche</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205955267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205955267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205955267">(Aug 04 2020 at 20:19)</a>:</h4>
<p>From what I can tell <code>rustc_span::Span</code> is very frequently used and has a size of 8 bytes without a niche.</p>
<p>Considering how many parts of the compiler use <code>Option&lt;Span&gt;</code> this seems like 4 to 8 lost bytes here</p>



<a name="205955396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205955396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205955396">(Aug 04 2020 at 20:20)</a>:</h4>
<p>Did someone already try to put a <code>NonZeroX</code> in there or is interested to try this while already being more familiar which how it works?</p>



<a name="205955455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205955455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205955455">(Aug 04 2020 at 20:21)</a>:</h4>
<p>otherwise I might try and look into this in the following weeks</p>



<a name="205956211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205956211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205956211">(Aug 04 2020 at 20:27)</a>:</h4>
<p>Also, how often do we hash spans, considering that we currently have 3 distinct hasher calls instead of 1 <code>u64</code></p>



<a name="205956337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205956337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205956337">(Aug 04 2020 at 20:28)</a>:</h4>
<p>which apperently prevents inlining when using the <code>DefaultHasher</code> (which we aren't doing in rustc afaik): <a href="https://rust.godbolt.org/z/v1rEqq">https://rust.godbolt.org/z/v1rEqq</a></p>



<a name="205956393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205956393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205956393">(Aug 04 2020 at 20:29)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> I would take a look at how rustc_index does things and see if we can't allocate 256 values at the upper end or so</p>



<a name="205960392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205960392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205960392">(Aug 04 2020 at 21:02)</a>:</h4>
<p>Hmm, yeah, from what I can <code>base_or_index</code> can spare 256values</p>



<a name="205960441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205960441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205960441">(Aug 04 2020 at 21:03)</a>:</h4>
<p>opened <a href="https://github.com/rust-lang/rust/issues/75164">#75164</a> for now which manually implements <code>PartialEq</code> and <code>Hash</code></p>



<a name="205962074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205962074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205962074">(Aug 04 2020 at 21:17)</a>:</h4>
<p>and pushed <code>Span</code> using a <code>newtype_index</code></p>



<a name="205962153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205962153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205962153">(Aug 04 2020 at 21:18)</a>:</h4>
<p>Does <code>#[rustc_scalar_valid_range]</code> automatically imply <code>repr(transparent)</code>? I sure hope so</p>



<a name="205962386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205962386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205962386">(Aug 04 2020 at 21:20)</a>:</h4>
<p>hm not sure</p>



<a name="205962402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205962402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205962402">(Aug 04 2020 at 21:20)</a>:</h4>
<p>but regardless we know that tuple structs of a single field aren't going anywhere</p>



<a name="205963738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/Span%20niche/near/205963738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/Span.20niche.html#205963738">(Aug 04 2020 at 21:35)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> not AFAIK but feel free to add <code>#[repr(transparent)]</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>